@extends('backstage.layout.master')
@section('title', '素材标签列表')
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a target="_blank" href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a target="_blank" href="/backstage/source-pic/source-pic-tag-list">素材标签列表</a>
            </li>
            <li>
                标签列表
            </li>
        </ul><!-- .breadcrumb -->

        <div class="nav-search" id="nav-search">
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                素材
                <small>
                    <i class="icon-double-angle-right"></i>
                    标签列表
                </small>
                <span class="pull-right">
                    <button class="btn btn-primary" onclick="javascript:window.location.href='{{asset('')}}backstage/source-pic/add-source-pic-tag';">添加素材标签</button>
                </span>
            </h1>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </th>
                            <th>编号</th>
                            <th>标签名</th>
                            <th>图标</th>
                            <th>子标签</th>
                            <th>范围</th>
                            <th>排序</th>
                            <th>更新时间</th>
                            <th style="text-align:center">操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach ($tags as $tag)
                        <tr class="" data-tr-id={{isset($tag->id)?$tag->id:0}}>
                            <td class="center">
                                <label>
                                    <input type="checkbox" name="tag_id" class="ace" value={{isset($tag->id)?$tag->id:0}} >
                                    <span class="lbl"></span>
                                </label>
                            </td>
                            <td>
                                <a target="_blank" href="/backstage/source-pic/get-source-pic-by-tag?id={{isset($tag->id)?$tag->id:0}}">{{isset($tag->id)?$tag->id:''}}</a>
                            </td>
                            <td>
                                <a target="_blank" href="/backstage/source-pic/get-source-pic-by-tag?id={{isset($tag->id)?$tag->id:0}}">{{isset($tag->name)?str_limit($tag->name, $limit = 8, $end = '...'):''}}</a>
                            </td>
                            <td class="hidden-480" align="center"><img src="/images/{{isset($tag->original_image)?$tag->original_image:''}}" width="100" ></td>
                            <td>
                                @if(isset($tag->has_sub_tag)&&($tag->has_sub_tag==true))
                                    有
                                @else
                                无
                                @endif
                            </td>
                            <td>
                                @if(isset($tag->tag_type)&&($tag->tag_type==1))
                                    全部
                                @else
                                    部分
                                @endif
                            </td>
                            <td style="width:68px;">
                                <input type="number" min=1 step=1 name="sort" value="{{$tag->sort}}" class="sort" style="width:50px;">
                                <input type="hidden" value="{{$tag->sort}}">
                                <input type="hidden" value="{{$tag->id}}">
                            </td>
                            <td>
                                {{isset($tag->updated_at)?date('Y-m-d H:i:s',$tag->updated_at):''}}
                            </td>
                            <td>
                                <ul class="nav-pills" style="list-style-type:none">
                                    <li class="dropdown all-camera-dropdown">
                                        <a style = "color: #2709ff" target="_blank" href="/backstage/source-pic/update-source-pic-tag?id={{isset($tag->id)?$tag->id:''}}">
                                            <span id="" style="font-weight: bold">编辑</span>
                                        </a>
                                    </li>
                                    @if(isset($tag->tag_type)&&($tag->tag_type!=1)&&(($tag->has_sub_tag==false)))
                                        <li data-filter-camera-type="Zed">
                                            <a style = "cursor:pointer;color: #000202;margin-left: 15px" target="_blank" href="/backstage/source-pic/bluk-add-source-pic?tag_id={{isset($tag->id)?$tag->id:''}}">
                                                <span id="" style="font-weight: bold">上传素材</span>
                                            </a>
                                        </li>
                                    @endif
                                    <li data-filter-camera-type="all">
                                        <a  data-delete="{{isset($tag->id)?$tag->id:0}}" style = "cursor:pointer;color: red;margin-left: 15px">
                                            <span style="font-weight: bold">删除</span>
                                        </a>
                                    </li>
                                </ul>
                            </td>
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $tags->render(); ?>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12" style="position: static;height: 50px;">
                        <span class="input-icon">
					   <select id="batch_processing_type"  style="width:209px;">
                            <option value =0>请选择 。。。。</option>
					   </select>
				     </span>
                        <span class="input-icon">
                        <input  type="button" value="确定" class="btn" id="batch_processing_submit" style="color:#0a03ff;">
                        </span>
                    </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        $(function () {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $('[data-rel=tooltip]').tooltip();
            $('[data-delete]').click(function(){
                var  id = $(this).attr("data-delete");
                if(id!==0){
                    swal({
                        title: "确定删除？？",
                        text: "",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        closeOnConfirm: true,
                        closeOnCancel: true
                    },function (){
                        $.ajax({
                            type: "POST",
                            url: "/backstage/source-pic/del-source-pic-tag",
                            data: {'id':id},
                            success: function (msg) {
                                if(msg.state=1){
                                    swal({title: "删除成功！", text: "",type: "success", timer:1000 });
                                    $('[data-tr-id='+id+']').remove();
                                }else {
                                    swal({title: msg.message, text: "",type: "error", timer:1000 });
                                }

                            }, error: function () {
                                swal({title: "系统繁忙！", text: "",type: "error", timer:1000 })
                            }
                        });
                    });
                }
            });
            $('table th input:checkbox').on('click' , function(){
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                        .each(function(){
                            this.checked = that.checked;
                            $(this).closest('tr').toggleClass('selected');
                        });

            });
       $('#batch_processing_type').change(function() {
                var type=$(this).val();
            });
       $('#batch_processing_submit').click(function() {
                var data = new Array();
                var i=0;
                $('table th input:checkbox').closest('table').find('tr > td:first-child input:checkbox')
                    .each(function(){
                        var tag_id=$(this).closest('tr').attr("data-tr-id");
                        if(tag_id!=0){
                            data.push(tag_id);
                        }
                    });
            });
       $(".sort").blur(function(){
                var sort = $(this).next().val();
                var newSort = $(this).val();
                var id = $(this).next().next().val();
                var a = $(this);
                if(newSort == sort){
                    return;
                }else{
                    $.ajax({
                        type: "POST",
                        url: "/backstage/tag/update-sort",
                        data:{"sort":newSort,"id":id},
                        success: function(msg){
                            if(msg.state==1){
                                swal({
                                    title: "更新成功！",
                                    text: "",
                                    type: "success",
                                    timer:2000
                                });
                                window.location.reload()
                            }else {
                                swal({
                                    title: msg.message,
                                    text: "",
                                    type: "error",
                                    timer:2000
                                });
                            }
                        },
                        error:function(){
                            swal({
                                title: "系统繁忙稍后再试",
                                text: "",
                                type: "error",
                                timer:2000
                            });
                        }
                    });
                }
            });
        });
    </script>
@stop